"""
@Project ：Python_Learning 
@File    ：88.合并两个有效数组.py
@IDE     ：PyCharm 
@Author  ：zhupp
@Date    ：2024/10/20 10:47 
"""
from typing import List


class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """

        if m + n > len(nums1):
            nums1.extend([0]*(m+n-len(nums1)))
        print(nums1)
        last = m + n - 1
        m = m - 1
        n = n - 1
        while m >= 0 and n >= 0:
            if nums1[m] > nums2[n]:
                nums1[last] = nums1[m]
                m -= 1
            else:
                nums1[last] = nums2[n]
                n -= 1
            last -= 1

        while n >= 0:
            nums1[last] = nums2[n]
            last -= 1
            n -= 1
        return nums1
s = Solution()
print(s.merge([1,2,3,0,0], m = 3, nums2 = [2,5,6], n = 3))